package itsbank;

import banks.CapitalMarketControl;
import database.DatabaseManager;
import exceptions.NotEnoughMoneyException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * the test driver of the program
 * @author Mike
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        /**
         * just a small test driver
         */
         ArrayList<Customer> customers = new ArrayList<Customer>();
        Iterator<Customer> it;

        ResultSet rs = DatabaseManager.getInstance().query("SELECT * FROM customers");
        while (rs.next()) {
            customers.add(DatabaseManager.getInstance().getCustomerByID(rs.getInt("ID")));
        }

        while (true) {
           it = customers.iterator();

            while (it.hasNext()) {
                try {
                    it.next().doSomething();
                }
                catch (NotEnoughMoneyException e) {
                    System.out.println("NotEnoughMoneyException happened! Aborting program!");
                    System.out.println("Affected account was: "+e.affectedAccount.getAccountNo());
                    System.exit(-1);
                }
            }
        }
    }

}
